// function findTarget(target) {
//   const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
//   let left = 0
//   let right = arr.length-1
//   // let center = (left+right) / 2
//   while( left < right ) {
//     // console.log('几次了')
//     let center = Math.floor((left+right) / 2)
//     const c = arr[center]
//     if(c === target) return center
//     if( c < target ) left = center + 1
//     if( c > target ) right = center - 1
//   }
//   return false
// }
// console.log( findTarget(9) )

// -----------------有序数组中大于target的第一个数字
// function findFT(target) {
//   const arr = [-1, 3, 3, 7, 10, 14, 14]
//   const length = arr.length
//   let leftIndex = 0 
//   let rightIndex = length - 1
//   while( leftIndex <= rightIndex ) {
//     const center = Math.floor((leftIndex+rightIndex) / 2)
//     const c = arr[center]
//     // console.log( c, center, leftIndex, rightIndex )
//     if( c> target && (!arr[center-1] || arr[center-1] <= target) ) {
//       // console.log(arr[center-1])
//       return c
//     }else if(c > target){
//       rightIndex = center -1
//     }else if(c <= target) {
//       leftIndex = center +1
//     }
//   }
// }

arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
function findFT(target) {
  const len = arr.length
  let left = 0
  let right = len - 1  

  while( left <= right ) {
    let middle = Math.floor((left + right)/2)
    if(target === arr[middle]) return middle
    if(arr[middle] > target) {
      right = middle
    }else{
      left = middle
    }    
  }
  return false
}

console.log( findFT(7) )